{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": true,
    "pycharm": {
     "is_executing": false
    }
   },
   "outputs": [],
   "source": [
    "from openpyxl import Workbook\n",
    "from datetime import datetime\n",
    "from openpyxl.drawing.image import Image\n",
    "from openpyxl.styles import Font"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "outputs": [
    {
     "data": {
      "text/plain": "<openpyxl.workbook.workbook.Workbook at 0x247f6d601d0>"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 28
    }
   ],
   "source": [
    "wb = Workbook() # 实例化对象\n",
    "wb"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "outputs": [
    {
     "data": {
      "text/plain": "<Worksheet \"Sheet\">"
     },
     "metadata": {},
     "output_type": "execute_result",
     "execution_count": 29
    }
   ],
   "source": [
    "# 正在活动的工作表\n",
    "ws = wb.active\n",
    "ws"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "outputs": [],
   "source": [
    "# 设置工作表\n",
    "ws.title = 'sheet1'"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "outputs": [],
   "source": [
    "# 左上角填入一和二\n",
    "ws.append(['一', '二'])\n",
    "ws.append([1, 2])\n",
    "# 日期格式，时间戳\n",
    "ws.append([datetime(2020,1,1),\n",
    "           datetime(2020,1,2)])\n",
    "# A4 表示 excel中的位置\n",
    "ws.add_image(Image('a.jpg'), 'A4')\n",
    "ws.add_image(Image('b.jpg'), 'B4')\n",
    "\n",
    "# 对A3字体更改一下颜色 16进制的RGB的三个值\n",
    "ws['A3'].font = Font(color='FF0000')\n",
    "\n",
    "wb.save('1.xlsx')\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n",
     "is_executing": false
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  },
  "pycharm": {
   "stem_cell": {
    "cell_type": "raw",
    "source": [],
    "metadata": {
     "collapsed": false
    }
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}